/*******************************************
 * Copyright 2007 Aphrodite Framework for javaME .
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v2.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * Email : owner@aphroditeme.dev.java.net
 * Contributors:
 *     Kent Elton - initial API and implementation
 *******************************************/

package com.aphrodite.ui.widgets;

import javax.microedition.lcdui.Graphics;

/**
 * Flashing text effect
 * 
 * @author kentelt
 * 
 */
public class FlashingText extends TextEffect {

	private volatile boolean textVisible = true;

	public FlashingText(Theme theme, String text) {
		super(theme, 0, 0);
		this.text = text;
		updateModel();
	}

	protected void doAniTask() {
		textVisible = !textVisible;
	}

	public void render(Graphics g) {
		if (!isVisible)
			return;
		capture(g, width, height, true);
		if (textVisible) {
			g.setFont(theme.widgetFont);
			g.setColor(theme.fgColor);
			g.drawString(text, 0, 0, 0);
		}
		release(g, width, height, false);
	}

	protected void updateModel() {
		this.width = theme.widgetFont.stringWidth(text);
		this.height = theme.widgetFont.getHeight();
	}

}
